﻿using AutoMapper;
using QYmall.Core.Model.Models;
using QYmall.Core.Model.ViewModels;

namespace QYmall.Core.Model.Profiles
{
    public class OAuthProfile : Profile
    {
        /// <summary>
        /// 授权登录实体映射
        /// </summary>
        public OAuthProfile()
        {
            //授权登录,将源数据映射到DTO
            CreateMap<OAuths, OAuthsDto>();
            CreateMap<OAuths, OAuthsEditDto>();
            //授权登录,将DTO映射到源数据
            CreateMap<OAuthsEditDto, OAuths>();

            //授权记录,将源数据映射到DTO
            CreateMap<OAuthLogin, OAuthLoginDto>()
                .ForMember(
                    dest => dest.UserName,
                    opt =>
                    {
                        opt.MapFrom(src => src.User != null ? src.User.UserName : null);
                    }
                ).ForMember(
                    dest => dest.OAuthTitle,
                    opt =>
                    {
                        opt.MapFrom(src => src.OAuth != null ? src.OAuth.Title : null);
                    }
                );
            CreateMap<OAuthLogin, OAuthLoginEditDto>();
            //授权记录,将DTO映射到源数据
            CreateMap<OAuthLoginEditDto, OAuthLogin>();
        }
    }
}
